package com.itheima.web.client.userlogincontrol.Userregistration;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 黄汉江
 * @date 2023/11/4 16:10
 * @description:
 */
@Repository
public interface UserRepository extends JpaRepository<User, Integer> {

    //    直接使用JPA生成的实现
//    @Query(value = "select c.* from t_customer c where c.username=?1", nativeQuery = true)
    User findByUsername(String username);

    @Query("select c from t_user c where c.username = ?1")
    public User findById2(String username);

    @Transactional
    @Modifying//JPA会以更新类语句来执行，而不再是以查询语句执行。
    @Query("UPDATE t_user c SET c.username = ?1 WHERE  c.id = ?2")
    public int updateUser(String username, Integer id);


    //5、根据评论id删除评论
    @Transactional
    @Modifying
    @Query("DELETE t_user c WHERE  c.id = ?1")
    public User deleteUser(Integer id);




}